<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initLogConfig() {
        $logger = new Zend_Log();
        //$writer = new Zend_Log_Writer_Firebug();
        //$logger->addWriter($writer);
        $fileWriter = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/logfile');
        $logger->addWriter($fileWriter);
        Zend_Registry::set('logger', $logger);
        return $logger;
    }

    protected function _initAutoload() {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace'=>'', 'basePath'=>dirname(__FILE__)
        ));
        return $autoloader;
    }

    protected function _initTimeZone() {
        date_default_timezone_set("America/Bogota");
        return date_default_timezone_get();
    }

    protected function _initLocale() {
        $locale = new Zend_Locale('es_CO');
        Zend_Registry::set('Zend_Locale', $locale);
        return $locale;
    }

    protected function _initAppConfig() {
        $appConfig = new Zend_Config($this->getOptions());
        Zend_Registry::set('appConfig', $appConfig);
        return $appConfig;
    }

    protected function _initDomConfig() {
        $domConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/dominios.ini', APPLICATION_ENV);
        Zend_Registry::set('domConfig', $domConfig);
        return $domConfig;
    }

    protected function _initActConfig() {
        $actionConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/actions.ini', APPLICATION_ENV);
        Zend_Registry::set('actionConfig', $actionConfig);
        return $actionConfig;
    }

    protected function _initTranslation() {
        $translator = new Zend_Translate(array(
            'adapter'=>'array', 'content'=>APPLICATION_PATH . '/langs', 'locale'=>'es',
            'scan'=>Zend_Translate::LOCALE_DIRECTORY
        ));
        Zend_Validate_Abstract::setDefaultTranslator($translator);
        return $translator;
    }

    /*protected function _initCache() {
        $frontendOptions = array(
            'automatic_serialization'=>true
        );
        $backendOptions = array();
        $cache = Zend_Cache::factory('Core', 'APC', $frontendOptions, $backendOptions);
        Zend_Registry::set('cache', $cache);
        Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
        return $cache;
    }*/

    protected function _initDbSession() {
        $resource = $this->getPluginResource('db');
        $db = $resource->getDbAdapter();
        //$db->query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
        $db->query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
        $db->query("ALTER SESSION SET NLS_TIME_FORMAT='HH24:MI:SS'");
        $db->query("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'");
        $db->query("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS  TZH:TZM'");
        $db->query("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'");
        return $db;
    }
}

